//
//  YSDownloadBookCellPresenter.m
//  YSDownLoadManager_Example
//
//  Created by Kyson on 2018/12/5.
//  Copyright © 2018 kysonyangs. All rights reserved.
//

#import "YSDownloadBookCellPresenter.h"

@interface YSDownloadBookCellPresenter ()

@property (nonatomic, weak) YSDownloadBookCell *cell;

@end

@implementation YSDownloadBookCellPresenter

- (void)bindWithCell:(YSDownloadBookCell *)cell {
    self.cell = cell;
    
    cell.bookNameLabel.text = self.bookModel.bookTitle;
    cell.totalSizeLabel.text = [self getFormatSizeWithSize:self.bookModel.totalSize];
    cell.stateLabel.text = self.bookModel.isDownload ? @"下载中" : @"下载完成";
    cell.progressView.progress = self.bookModel.progress;
    cell.progressLabel.text = [NSString stringWithFormat:@"%.0f%%",self.bookModel.progress * 100];        
}

- (NSString *)getFormatSizeWithSize: (long long)fileSize {
    NSArray *unit = @[@"B", @"kb", @"M", @"G"];
    
    double tmpSize = fileSize;
    int index = 0;
    while (tmpSize > 1024) {
        tmpSize /= 1024;
        index ++;
    }
    return [NSString stringWithFormat:@"%.1f%@",tmpSize, unit[index]];
}

@end
